import presetWeapp from 'unocss-preset-weapp'
import {extractorAttributify, transformerClass} from 'unocss-preset-weapp/transformer'
import {defineConfig} from 'unocss'
import transformerDirectives from '@unocss/transformer-directives'
import {
    presetRemRpx,
} from 'unocss-applet'

const {presetWeappAttributify, transformerAttributify} = extractorAttributify()

// uni-app
const isApplet = process.env?.UNI_PLATFORM?.startsWith('mp') ?? false

const presets = []
if (isApplet) {
    presets.push(presetRemRpx())
} else {
    presets.push(presetRemRpx({mode: 'rpx2rem'}))
}

export default defineConfig({
    presets: [
        // https://github.com/MellowCo/unocss-preset-weapp
        presetWeapp(),
        // 属性自动补全(attributify autocomplete)
        presetWeappAttributify(),
        ...presets
    ],
    shortcuts: [
        {
            'center': 'flex justify-center items-center',
        },
    ],
    transformers: [
        // 启用 @apply 功能
        transformerDirectives({
            applyVariable: ['--at-apply', '--uno-apply', '--uno', '--ay'],
        }),
        // https://github.com/MellowCo/unocss-preset-weapp/tree/main/src/transformer/transformerAttributify
        transformerAttributify(),

        // https://github.com/MellowCo/unocss-preset-weapp/tree/main/src/transformer/transformerClass
        transformerClass(),
    ]
})